/**
 * @author David Milne
 */

function Koru() {
	logDebug("Koru created");
	
	this.queryResultsTray ;
	this.documentsTray ;
	
	this.searchBox ;
	
	this.topicColors = new Array() ; 
	this.topicColors.push("rgb(245,150,30)") ;
  	this.topicColors.push("rgb(255,240,0)") ;
  	this.topicColors.push("rgb(140,200,60)") ;
  	this.topicColors.push("rgb(55,180,75)") ;
  	this.topicColors.push("rgb(0,165,80)") ;
  	this.topicColors.push("rgb(0,170,160)") ;
  	this.topicColors.push("rgb(0,175,240)") ;
  	this.topicColors.push("rgb(0,115,190)") ;
  	this.topicColors.push("rgb(0,85,165)") ;
  	this.topicColors.push("rgb(50,50,145)") ;
  	this.topicColors.push("rgb(100,45,145)") ;
  	this.topicColors.push("rgb(145,40,145)") ;
  	this.topicColors.push("rgb(240,0,140)") ;
  	this.topicColors.push("rgb(245,15,90)") ;
}


Koru.prototype.init = koru_init ;
Koru.prototype.resize = koru_resize ;
Koru.prototype.getHighlightColor = koru_getHighlightColor ;

function koru_init() {
	try {
		this.id = "koru" ;
		
		var logo = document.createElement("div") ;
		logo.className = "logo"  ;
		//logo.onclick = new Function("MochiKit.Logging.logger.debuggingBookmarklet()") ;
		this.appendChild(logo) ;
		
		this.searchBox = document.applyInherit(document.createElement("div"), new SearchBox()) ;
		this.appendChild(this.searchBox) ;
		this.searchBox.init() ;
		
		/*		
		var table = document.createElement("table") ;
		table.className = "linksTable" ;
		this.appendChild(table) ;
		
		var row = table.insertRow(0) ;
  		var cell = row.insertCell(0) ;
  		cell.innerHTML = "<em>" + collectionName + "</em>" ;
		cell = row.insertCell(1) ;
		cell.innerHTML = "<a href='settings.html'>Settings</a> " ;
		cell = row.insertCell(2) ;
		cell.innerHTML = "<a href='help.html'>Help</a> " ;
		cell = row.insertCell(3) ;
		cell.innerHTML = "<a href='javascript:MochiKit.Logging.logger.debuggingBookmarklet()'>Debug</a> " ;
  
  		//this.queryTopicsTray = document.applyInherit(document.createElement("div"), new QueryTopicsTray()) ;
		//this.queryTopicsTray.init() ;
		*/
		
		this.queryResultsTray = document.applyInherit(document.createElement("div"), new QueryResultsTray()) ;
		this.queryResultsTray.init() ;
		this.appendChild(this.queryResultsTray) ;
		
		this.documentsTray = document.applyInherit(document.createElement("div"), new DocumentsTray()) ;
		this.documentsTray.init() ;
		this.appendChild(this.documentsTray) ;
		
		//this.traySlider = document.applyInherit(document.createElement("div"), new TraySlider()) ;
		//this.traySlider.init(this.queryTopicsTray, this.queryResultsTray, this.documentsTray) ;
		//this.appendChild(this.traySlider) ;
		
		this.searchBox.setFocus() ;
		
	} catch ( e ) { 
		logError("koru.init.error: " + e ); 
		throw (e) ;
	}
} 
  
function koru_resize(w, h) {
	try {
		
		var trayWidth = (w/2)-15 ;
		
		this.searchBox.resize(w - 500) ;
		
		this.style.width = w + "px" ;
		this.style.height = h + "px" ;
		
		this.queryResultsTray.resize(trayWidth, h - 100) ;
		this.documentsTray.resize(trayWidth, h - 100) ;
		this.documentsTray.style.left = trayWidth + 20 + "px" ;
	} catch (e) {
		logError("koru.resize.error: " + e) ;
		throw (e) ;
	}
}

function koru_getHighlightColor(index) {
	
	return getAverageColor(this.topicColors[index], "rgb(255,255,255)") ;
}